home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH11 / SRC / TRANS2.FRM < prev    next >
Text File  |  1996-05-02  |  24KB  |  839 lines

  1. VERSION 4.00
  2. Begin VB.Form RotatedForm 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Surfaces of Rotation"
  6.    ClientHeight    =   5700
  7.    ClientLeft      =   630
  8.    ClientTop       =   900
  9.    ClientWidth     =   7830
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   1
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   6390
  21.    KeyPreview      =   -1  'True
  22.    Left            =   570
  23.    LinkTopic       =   "Form1"
  24.    ScaleHeight     =   380
  25.    ScaleMode       =   3  'Pixel
  26.    ScaleWidth      =   522
  27.    Top             =   270
  28.    Width           =   7950
  29.    Begin VB.CheckBox HideCheck 
  30.       Caption         =   "Remove Hidden Surfaces"
  31.       Height          =   255
  32.       Left            =   0
  33.       TabIndex        =   23
  34.       Top             =   5400
  35.       Width           =   2505
  36.    End
  37.    Begin VB.Frame Frame2 
  38.       Caption         =   "Curve"
  39.       Height          =   5295
  40.       Left            =   0
  41.       TabIndex        =   8
  42.       Top             =   0
  43.       Width           =   2295
  44.       Begin VB.OptionButton CurveChoice 
  45.          Caption         =   "Tornado"
  46.          Height          =   255
  47.          Index           =   13
  48.          Left            =   120
  49.          TabIndex        =   22
  50.          Top             =   4920
  51.          Width           =   2055
  52.       End
  53.       Begin VB.OptionButton CurveChoice 
  54.          Caption         =   "Helix"
  55.          Height          =   255
  56.          Index           =   12
  57.          Left            =   120
  58.          TabIndex        =   21
  59.          Top             =   4560
  60.          Width           =   2055
  61.       End
  62.       Begin VB.OptionButton CurveChoice 
  63.          Caption         =   "Tower"
  64.          Height          =   255
  65.          Index           =   11
  66.          Left            =   120
  67.          TabIndex        =   20
  68.          Top             =   4200
  69.          Width           =   2055
  70.       End
  71.       Begin VB.OptionButton CurveChoice 
  72.          Caption         =   "Football"
  73.          Height          =   255
  74.          Index           =   10
  75.          Left            =   120
  76.          TabIndex        =   19
  77.          Top             =   3840
  78.          Width           =   2055
  79.       End
  80.       Begin VB.OptionButton CurveChoice 
  81.          Caption         =   "Goblet"
  82.          Height          =   255
  83.          Index           =   9
  84.          Left            =   120
  85.          TabIndex        =   18
  86.          Top             =   3480
  87.          Width           =   2055
  88.       End
  89.       Begin VB.OptionButton CurveChoice 
  90.          Caption         =   "Urn"
  91.          Height          =   255
  92.          Index           =   8
  93.          Left            =   120
  94.          TabIndex        =   17
  95.          Top             =   3120
  96.          Width           =   2055
  97.       End
  98.       Begin VB.OptionButton CurveChoice 
  99.          Caption         =   "Sine Wave"
  100.          Height          =   255
  101.          Index           =   7
  102.          Left            =   120
  103.          TabIndex        =   16
  104.          Top             =   2760
  105.          Width           =   2055
  106.       End
  107.       Begin VB.OptionButton CurveChoice 
  108.          Caption         =   "Semicircle 2"
  109.          Height          =   255
  110.          Index           =   6
  111.          Left            =   120
  112.          TabIndex        =   15
  113.          Top             =   2400
  114.          Width           =   2055
  115.       End
  116.       Begin VB.OptionButton CurveChoice 
  117.          Caption         =   "Semicircle 1"
  118.          Height          =   255
  119.          Index           =   5
  120.          Left            =   120
  121.          TabIndex        =   14
  122.          Top             =   2040
  123.          Width           =   2055
  124.       End
  125.       Begin VB.OptionButton CurveChoice 
  126.          Caption         =   "Circle 2"
  127.          Height          =   255
  128.          Index           =   4
  129.          Left            =   120
  130.          TabIndex        =   13
  131.          Top             =   1680
  132.          Width           =   2055
  133.       End
  134.       Begin VB.OptionButton CurveChoice 
  135.          Caption         =   "Circle 1"
  136.          Height          =   255
  137.          Index           =   3
  138.          Left            =   120
  139.          TabIndex        =   12
  140.          Top             =   1320
  141.          Width           =   2055
  142.       End
  143.       Begin VB.OptionButton CurveChoice 
  144.          Caption         =   "3/4 Rectangle"
  145.          Height          =   255
  146.          Index           =   2
  147.          Left            =   120
  148.          TabIndex        =   11
  149.          Top             =   960
  150.          Width           =   2055
  151.       End
  152.       Begin VB.OptionButton CurveChoice 
  153.          Caption         =   "Diamond"
  154.          Height          =   255
  155.          Index           =   1
  156.          Left            =   120
  157.          TabIndex        =   10
  158.          Top             =   600
  159.          Width           =   2055
  160.       End
  161.       Begin VB.OptionButton CurveChoice 
  162.          Caption         =   "Rectangle"
  163.          Height          =   255
  164.          Index           =   0
  165.          Left            =   120
  166.          TabIndex        =   9
  167.          Top             =   240
  168.          Value           =   -1  'True
  169.          Width           =   2055
  170.       End
  171.    End
  172.    Begin VB.CheckBox ShowAxesCheck 
  173.       Caption         =   "Show Axes"
  174.       Height          =   255
  175.       Left            =   2520
  176.       TabIndex        =   7
  177.       Top             =   5400
  178.       Width           =   1335
  179.    End
  180.    Begin VB.TextBox PhiText 
  181.       Height          =   285
  182.       Left            =   6960
  183.       TabIndex        =   6
  184.       Text            =   "0.1570"
  185.       Top             =   5400
  186.       Width           =   855
  187.    End
  188.    Begin VB.TextBox ThetaText 
  189.       Height          =   285
  190.       Left            =   5640
  191.       TabIndex        =   4
  192.       Text            =   "0.6283"
  193.       Top             =   5400
  194.       Width           =   855
  195.    End
  196.    Begin VB.TextBox RText 
  197.       Height          =   285
  198.       Left            =   4080
  199.       TabIndex        =   2
  200.       Text            =   "10"
  201.       Top             =   5400
  202.       Width           =   855
  203.    End
  204.    Begin VB.PictureBox Pict 
  205.       AutoRedraw      =   -1  'True
  206.       BackColor       =   &H00C0C0C0&
  207.       ForeColor       =   &H00000000&
  208.       Height          =   5295
  209.       Left            =   2400
  210.       ScaleHeight     =   349
  211.       ScaleMode       =   3  'Pixel
  212.       ScaleWidth      =   357
  213.       TabIndex        =   0
  214.       Top             =   0
  215.       Width           =   5415
  216.    End
  217.    Begin MSComDlg.CommonDialog LoadDialog 
  218.       Left            =   1800
  219.       Top             =   5280
  220.       _version        =   65536
  221.       _extentx        =   847
  222.       _extenty        =   847
  223.       _stockprops     =   0
  224.       cancelerror     =   -1  'True
  225.    End
  226.    Begin VB.Label Label1 
  227.       Caption         =   "Phi"
  228.       Height          =   255
  229.       Index           =   2
  230.       Left            =   6600
  231.       TabIndex        =   5
  232.       Top             =   5415
  233.       Width           =   375
  234.    End
  235.    Begin VB.Label Label1 
  236.       Caption         =   "Theta"
  237.       Height          =   255
  238.       Index           =   1
  239.       Left            =   5040
  240.       TabIndex        =   3
  241.       Top             =   5415
  242.       Width           =   495
  243.    End
  244.    Begin VB.Label Label1 
  245.       Caption         =   "R"
  246.       Height          =   255
  247.       Index           =   0
  248.       Left            =   3840
  249.       TabIndex        =   1
  250.       Top             =   5415
  251.       Width           =   255
  252.    End
  253.    Begin VB.Menu mnuFile 
  254.       Caption         =   "&File"
  255.       Begin VB.Menu mnuFileLoad 
  256.          Caption         =   "&Load..."
  257.          Shortcut        =   ^L
  258.       End
  259.       Begin VB.Menu mnuFileSaveAs 
  260.          Caption         =   "Save &As..."
  261.          Shortcut        =   ^A
  262.       End
  263.       Begin VB.Menu mnuFileSaveAsSolid 
  264.          Caption         =   "Save As &Solid..."
  265.       End
  266.       Begin VB.Menu mnuFileSep 
  267.          Caption         =   "-"
  268.       End
  269.       Begin VB.Menu mnuFileExit 
  270.          Caption         =   "E&xit"
  271.       End
  272.    End
  273. End
  274. Attribute VB_Name = "RotatedForm"
  275. Attribute VB_Creatable = False
  276. Attribute VB_Exposed = False
  277. Option Explicit
  278.  
  279. ' Location of viewing eye.
  280. Dim EyeR As Single
  281. Dim EyeTheta As Single
  282. Dim EyePhi As Single
  283.  
  284. Const dtheta = PI / 20
  285. Const Dphi = PI / 20
  286. Const Dr = 1
  287.  
  288. ' Location of focus point.
  289. Const FocusX = 0#
  290. Const FocusY = 0#
  291. Const FocusZ = 0#
  292.  
  293. Dim Projector(1 To 4, 1 To 4) As Single
  294.  
  295. Dim CurveNum As Integer
  296.  
  297. Dim ThePicture As ObjPicture
  298. Dim TheSurface As ObjTransformed
  299.  
  300. Dim ShowingParameters As Boolean
  301.  
  302. ' ************************************************
  303. ' Create the selected curve.
  304. ' ************************************************
  305. Sub CreateCurve()
  306. Dim r As Single
  307. Dim offset As Single
  308. Dim dtheta As Single
  309. Dim theta As Single
  310. Dim Y As Single
  311.  
  312.     Select Case CurveNum
  313.         Case 0  ' Rectangle.
  314.             TheSurface.AddCurvePoint -3, -1.5, 0
  315.             TheSurface.AddCurvePoint -1, -1.5, 0
  316.             TheSurface.AddCurvePoint -1, 1.5, 0
  317.             TheSurface.AddCurvePoint -3, 1.5, 0
  318.             TheSurface.AddCurvePoint -3, -1.5, 0
  319.  
  320.         Case 1  ' Diamond.
  321.             TheSurface.AddCurvePoint -3, 0, 0
  322.             TheSurface.AddCurvePoint -2, -1, 0
  323.             TheSurface.AddCurvePoint -1, 0, 0
  324.             TheSurface.AddCurvePoint -2, 1, 0
  325.             TheSurface.AddCurvePoint -3, 0, 0
  326.         
  327.         Case 2  ' 3/4 Rectangle.
  328.             TheSurface.AddCurvePoint 0, 1.5, 0
  329.             TheSurface.AddCurvePoint -3, 1.5, 0
  330.             TheSurface.AddCurvePoint -3, -1.5, 0
  331.             TheSurface.AddCurvePoint 0, -1.5, 0
  332.         
  333.         Case 3, 4   ' Circle 1, circle 2.
  334.             If CurveNum = 3 Then
  335.                 r = 2
  336.                 offset = 2
  337.             Else
  338.                 r = 1.5
  339.                 offset = 2.5
  340.             End If
  341.             dtheta = PI / 8
  342.             TheSurface.AddCurvePoint offset + r, 0, 0
  343.             For theta = -dtheta To -2 * PI + dtheta - 0.1 Step -dtheta
  344.                 TheSurface.AddCurvePoint _
  345.                     offset + r * Cos(theta), r * Sin(theta), 0
  346.             Next theta
  347.             TheSurface.AddCurvePoint offset + r, 0, 0
  348.         
  349.         Case 5, 6   ' Semicircle 1, semicircle 2.
  350.             If CurveNum = 5 Then
  351.                 r = 4
  352.                 offset = 0
  353.             Else
  354.                 r = 2
  355.                 offset = 2
  356.             End If
  357.             dtheta = PI / 8
  358.             If CurveNum = 6 Then _
  359.                 TheSurface.AddCurvePoint 0, r, 0
  360.             For theta = PI / 2 To -PI / 2 + dtheta - 0.1 Step -dtheta
  361.                 TheSurface.AddCurvePoint _
  362.                     offset + r * Cos(theta), _
  363.                     r * Sin(theta), _
  364.                     0
  365.             Next theta
  366.             TheSurface.AddCurvePoint offset, -r, 0
  367.             If CurveNum = 6 Then _
  368.                 TheSurface.AddCurvePoint 0, -r, 0
  369.  
  370.         Case 7  ' Sine wave.
  371.             r = 0.7
  372.             dtheta = PI / 10
  373.             TheSurface.AddCurvePoint 0, PI, 0
  374.             For theta = PI To -PI Step -dtheta
  375.                 TheSurface.AddCurvePoint _
  376.                     1 + r + r * Sin(2 * theta), _
  377.                     theta, _
  378.                     0
  379.             Next theta
  380.             TheSurface.AddCurvePoint 0, theta + dtheta, 0
  381.             
  382.         Case 8  ' Urn.
  383.             dtheta = PI / 10
  384.             TheSurface.AddCurvePoint 0, PI, 0
  385.             For theta = PI To -PI Step -dtheta
  386.                 TheSurface.AddCurvePoint _
  387.                     PI / 2 + (-PI + theta) / 4 * Sin(2 * theta), _
  388.                     theta, _
  389.                     0
  390.             Next theta
  391.             TheSurface.AddCurvePoint 0, theta + dtheta, 0
  392.             
  393.         Case 9  ' Goblet.
  394.             TheSurface.AddCurvePoint 0, 3.5, 0
  395.             TheSurface.AddCurvePoint 3, 3.5, 0
  396.             TheSurface.AddCurvePoint 2.5, 3, 0
  397.             TheSurface.AddCurvePoint 3, 1.5, 0
  398.             TheSurface.AddCurvePoint 2.5, 1, 0
  399.             TheSurface.AddCurvePoint 1, 1, 0
  400.             TheSurface.AddCurvePoint 0.5, 0.5, 0
  401.             TheSurface.AddCurvePoint 0.5, -1, 0
  402.             TheSurface.AddCurvePoint 1, -1.5, 0
  403.             TheSurface.AddCurvePoint 2, -1.5, 0
  404.             TheSurface.AddCurvePoint 2.5, -2, 0
  405.             TheSurface.AddCurvePoint 0, -2, 0
  406.         
  407.         Case 10 ' Football.
  408.             For Y = 4 To -4 Step -0.5
  409.                 TheSurface.AddCurvePoint 16 / 5 - Y * Y / 5, Y, 0
  410.             Next Y
  411.         
  412.         Case 11 ' Tower.
  413.             r = 1
  414.             dtheta = PI / 8
  415.             For theta = -PI To -PI / 2 Step dtheta
  416.                 TheSurface.AddCurvePoint _
  417.                     r + r * Cos(theta), _
  418.                     4 * r + r * Sin(theta), _
  419.                     0
  420.             Next theta
  421.             For theta = PI / 2 To -PI / 2 Step -dtheta
  422.                 TheSurface.AddCurvePoint _
  423.                     r + r * Cos(theta), _
  424.                     2 * r + r * Sin(theta), _
  425.                     0
  426.             Next theta
  427.             TheSurface.AddCurvePoint r, -3, 0
  428.             TheSurface.AddCurvePoint 0, -3, 0
  429.         
  430.         Case 12 ' Helix.
  431.             r = 2
  432.             dtheta = PI / 4
  433.             TheSurface.AddCurvePoint 0, PI, 0
  434.             For theta = PI To -PI Step -dtheta
  435.                 TheSurface.AddCurvePoint _
  436.                     r * Cos(theta / 2), _
  437.                     theta, _
  438.                     r * Sin(theta / 2)
  439.             Next theta
  440.             TheSurface.AddCurvePoint 0, theta + dtheta, 0
  441.         
  442.         Case 13 ' Tornado.
  443.             r = 2
  444.             dtheta = PI / 4
  445.             TheSurface.AddCurvePoint 0, PI, 0
  446.             For theta = PI To -PI Step -dtheta
  447.                 r = 2 + theta / 2
  448.                 TheSurface.AddCurvePoint _
  449.                     r * Cos(theta / 2), _
  450.                     theta, _
  451.                     r * Sin(theta / 2)
  452.             Next theta
  453.             TheSurface.AddCurvePoint 0, theta + dtheta, 0
  454.     
  455.     End Select
  456. End Sub
  457.  
  458. ' ************************************************
  459. ' Create the transformation.
  460. ' ************************************************
  461. Sub CreateTransformation()
  462. Dim t(1 To 4, 1 To 4) As Single
  463. Dim theta As Single
  464. Dim dtheta As Single
  465. Dim i As Integer
  466.             
  467.     dtheta = 2 * PI / 12
  468.     For i = 1 To 12
  469.         theta = i * dtheta
  470.         m3YRotate t, theta      ' Rotate.
  471.         TheSurface.SetTrans t
  472.     Next i
  473. End Sub
  474.  
  475.  
  476. Sub WaitEnd()
  477.     MousePointer = vbDefault
  478. End Sub
  479.  
  480. Sub WaitStart()
  481.     MousePointer = vbHourglass
  482.     DoEvents
  483. End Sub
  484.  
  485. ' ************************************************
  486. ' Create a new curve and rotate it.
  487. ' ************************************************
  488. Private Sub CurveChoice_Click(Index As Integer)
  489. Dim pline As ObjPolyline
  490.  
  491.     WaitStart
  492.     Set ThePicture = New ObjPicture
  493.     Set TheSurface = New ObjTransformed
  494.     ThePicture.Objects.Add TheSurface
  495.     
  496.     CurveNum = Index
  497.     CreateCurve
  498.     CreateTransformation
  499.     
  500.     TheSurface.Transform False
  501.     
  502.     If ShowAxesCheck.value = vbChecked Then
  503.         Set pline = New ObjPolyline
  504.         ThePicture.Objects.Add pline
  505.         pline.AddSegment 0, 0, 0, 5, 0, 0
  506.         pline.AddSegment 0, 0, 0, 0, 5, 0
  507.         pline.AddSegment 0, 0, 0, 0, 0, 5
  508.     End If
  509.     
  510.     DrawData Pict
  511.     Pict.SetFocus
  512. End Sub
  513.  
  514. ' ************************************************
  515. ' Display the data.
  516. ' ************************************************
  517. Private Sub DrawData(pic As Object)
  518. Dim x As Single
  519. Dim Y As Single
  520. Dim z As Single
  521. Dim S(1 To 4, 1 To 4) As Single
  522. Dim t(1 To 4, 1 To 4) As Single
  523. Dim ST(1 To 4, 1 To 4) As Single
  524. Dim PST(1 To 4, 1 To 4) As Single
  525. Dim edge_pen As Long
  526. Dim old_pen As Long
  527. Dim fill_brush As Long
  528. Dim old_brush As Long
  529. Dim status As Long
  530.  
  531.     MousePointer = vbHourglass
  532.     Refresh
  533.     
  534.     ' Prevent overflow errors when drawing lines
  535.     ' too far out of bounds.
  536.     On Error Resume Next
  537.     
  538.     ' Scale and translate so it looks OK in pixels.
  539.     m3Scale S, 35, -35, 1
  540.     m3Translate t, 180, 200, 0
  541.     m3MatMultiplyFull ST, S, t
  542.     m3MatMultiplyFull PST, Projector, ST
  543.     
  544.     ' If we are removing hidden surfaces, cull now.
  545.     If HideCheck.value = vbChecked Then
  546.         m3SphericalToCartesian EyeR, EyeTheta, EyePhi, x, Y, z
  547.         ThePicture.Cull x, Y, z
  548.     Else
  549.         ThePicture.Culled = False
  550.     End If
  551.     
  552.     ' Transform the points.
  553.     ThePicture.ApplyFull PST
  554.  
  555.     ' Display the data.
  556.     pic.Cls
  557.     If HideCheck.value = vbChecked Then
  558.         m3SphericalToCartesian EyeR, EyeTheta, EyePhi, x, Y, z
  559.         ThePicture.Cull x, Y, z
  560.         
  561.         ' Get a pen and brush.
  562.         edge_pen = CreatePen(PS_SOLID, pic.DrawWidth, pic.ForeColor)
  563.         old_pen = SelectObject(pic.hdc, edge_pen)
  564.         fill_brush = CreateSolidBrush(pic.BackColor)
  565.         old_brush = SelectObject(pic.hdc, fill_brush)
  566.         
  567.         ThePicture.DrawOrdered pic, EyeR
  568.  
  569.         ' Restore the old pen and brush.
  570.         edge_pen = SelectObject(pic.hdc, old_pen)
  571.         fill_brush = SelectObject(pic.hdc, old_brush)
  572.         status = DeleteObject(edge_pen)
  573.         status = DeleteObject(fill_brush)
  574.     Else
  575.         ThePicture.Draw pic, EyeR
  576.     End If
  577.     pic.Refresh
  578.  
  579.     ' Display the viewnig parameters.
  580.     ShowViewingParameters
  581.  
  582.     MousePointer = vbDefault
  583. End Sub
  584.  
  585. Sub ShowViewingParameters()
  586.     ShowingParameters = True
  587.     
  588.     RText.Text = Format$(EyeR, "0.0000")
  589.     ThetaText.Text = Format$(EyeTheta, "0.0000")
  590.     PhiText.Text = Format$(EyePhi, "0.0000")
  591.     
  592.     RText.Refresh
  593.     ThetaText.Refresh
  594.     PhiText.Refresh
  595.  
  596.     ShowingParameters = False
  597. End Sub
  598.  
  599. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  600.     Select Case KeyCode
  601.         Case vbKeyLeft
  602.             EyeTheta = EyeTheta - dtheta
  603.         
  604.         Case vbKeyRight
  605.             EyeTheta = EyeTheta + dtheta
  606.         
  607.         Case vbKeyUp
  608.             EyePhi = EyePhi - Dphi
  609.         
  610.         Case vbKeyDown
  611.             EyePhi = EyePhi + Dphi
  612.                 
  613.         Case Else
  614.             Exit Sub
  615.     End Select
  616.  
  617.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  618.     DrawData Pict
  619. End Sub
  620.  
  621.  
  622. Private Sub Form_KeyPress(KeyAscii As Integer)
  623.     Select Case KeyAscii
  624.         Case Asc("+")
  625.             EyeR = EyeR + Dr
  626.         
  627.         Case Asc("-")
  628.             EyeR = EyeR - Dr
  629.         
  630.         Case Else
  631.             Exit Sub
  632.     End Select
  633.  
  634.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  635.     DrawData Pict
  636. End Sub
  637.  
  638. Private Sub Form_Load()
  639.     ' Initialize the eye position.
  640.     EyeR = 10
  641.     EyeTheta = PI * 0.2
  642.     EyePhi = PI * 0.1
  643.     
  644.     ' Initialize the projection transformation.
  645.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  646.  
  647.     Me.Show
  648.     CurveChoice_Click 0
  649. End Sub
  650.  
  651.  
  652. Private Sub mnuFileExit_Click()
  653.     Unload Me
  654. End Sub
  655.  
  656.  
  657. Private Sub mnuFileLoad_Click()
  658. Dim fname As String
  659. Dim filenum As Integer
  660. Dim txt As String
  661. Dim Xmin As Single
  662. Dim ymin As Single
  663. Dim xmax As Single
  664. Dim ymax As Single
  665. Dim i As Integer
  666.  
  667.     ' Allow the user to pick a file.
  668.     On Error Resume Next
  669.     LoadDialog.filename = "*.APF"
  670.     LoadDialog.ShowOpen
  671.     If Err.Number = cdlCancel Then
  672.         Unload LoadDialog
  673.         Exit Sub
  674.     ElseIf Err.Number <> 0 Then
  675.         Unload LoadDialog
  676.         Beep
  677.         MsgBox "Error selecting file.", , vbExclamation
  678.         Exit Sub
  679.     End If
  680.     On Error GoTo 0
  681.     
  682.     fname = LoadDialog.filename
  683.     LoadDialog.InitDir = Left$(fname, Len(fname) _
  684.         - Len(LoadDialog.FileTitle) - 1)
  685.  
  686.     ' Clear the picture.
  687.     Set ThePicture = Nothing
  688.     
  689.     ' Open the file.
  690.     filenum = FreeFile
  691.     Open fname For Input As #filenum
  692.     
  693.     ' Make sure it's an Object Picture File.
  694.     Input #filenum, txt
  695.     If txt <> "3D APF PICTURE" Then
  696.         Close filenum
  697.         Beep
  698.         MsgBox "Error reading file """ & fname & """.", , vbExclamation
  699.         Exit Sub
  700.     End If
  701.  
  702.     ' Read the picture.
  703.     MousePointer = vbHourglass
  704.     DoEvents
  705.     Set ThePicture = New ObjPicture
  706.     ThePicture.FileInput filenum
  707.     
  708.     ' Close the file.
  709.     Close filenum
  710.  
  711.     ' Refresh the display.
  712.     DrawData Pict
  713.     
  714.     ' Deselect all the option buttons.
  715.     For i = 0 To 13
  716.         If CurveChoice(i).value Then _
  717.             CurveChoice(i).value = False
  718.     Next i
  719.  
  720.     MousePointer = vbDefault
  721. End Sub
  722.  
  723. ' ************************************************
  724. ' Allow the user to save the ObjTransformed
  725. ' object's display solid.
  726. ' ************************************************
  727. Private Sub mnuFileSaveAsSolid_Click()
  728. Dim fname As String
  729. Dim filenum As Integer
  730.  
  731.     ' Allow the user to pick a file.
  732.     On Error Resume Next
  733.     LoadDialog.filename = "*.APF"
  734.     LoadDialog.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly
  735.     LoadDialog.ShowSave
  736.     If Err.Number = cdlCancel Then
  737.         Unload LoadDialog
  738.         Exit Sub
  739.     ElseIf Err.Number <> 0 Then
  740.         Unload LoadDialog
  741.         Beep
  742.         MsgBox "Error selecting file.", , vbExclamation
  743.         Exit Sub
  744.     End If
  745.     On Error GoTo 0
  746.     
  747.     fname = LoadDialog.filename
  748.     LoadDialog.InitDir = Left$(fname, Len(fname) _
  749.         - Len(LoadDialog.FileTitle) - 1)
  750.     
  751.     ' Open the file.
  752.     filenum = FreeFile
  753.     Open fname For Output As #filenum
  754.     
  755.     ' Write the picture.
  756.     Write #filenum, "3D APF PICTURE"
  757.     Write #filenum, 1
  758.     TheSurface.FileWriteSolid filenum
  759.     
  760.     ' Close the file.
  761.     Close filenum
  762. End Sub
  763.  
  764. ' ************************************************
  765. ' Allow the user to save the ObjTransformed object.
  766. ' ************************************************
  767. Private Sub mnuFileSaveAs_Click()
  768. Dim fname As String
  769. Dim filenum As Integer
  770.  
  771.     ' Allow the user to pick a file.
  772.     On Error Resume Next
  773.     LoadDialog.filename = "*.APF"
  774.     LoadDialog.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly
  775.     LoadDialog.ShowSave
  776.     If Err.Number = cdlCancel Then
  777.         Unload LoadDialog
  778.         Exit Sub
  779.     ElseIf Err.Number <> 0 Then
  780.         Unload LoadDialog
  781.         Beep
  782.         MsgBox "Error selecting file.", , vbExclamation
  783.         Exit Sub
  784.     End If
  785.     On Error GoTo 0
  786.     
  787.     fname = LoadDialog.filename
  788.     LoadDialog.InitDir = Left$(fname, Len(fname) _
  789.         - Len(LoadDialog.FileTitle) - 1)
  790.     
  791.     ' Open the file.
  792.     filenum = FreeFile
  793.     Open fname For Output As #filenum
  794.     
  795.     ' Write the picture.
  796.     ThePicture.FileWrite filenum
  797.     
  798.     ' Close the file.
  799.     Close filenum
  800. End Sub
  801.  
  802. Private Sub PhiText_Change()
  803.     If ShowingParameters Then Exit Sub
  804.     EyePhi = CSng(PhiText.Text)
  805.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  806.     DrawData Pict
  807. End Sub
  808.  
  809.  
  810. Private Sub RText_Change()
  811.     If ShowingParameters Then Exit Sub
  812.     EyeR = CSng(RText.Text)
  813.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  814.     DrawData Pict
  815. End Sub
  816.  
  817.  
  818. ' ************************************************
  819. ' Redraw with the hidden surfaces on or off.
  820. ' ************************************************
  821. Private Sub HideCheck_Click()
  822.     DrawData Pict
  823. End Sub
  824. ' ************************************************
  825. ' Redraw with the axes on or off as appropriate.
  826. ' ************************************************
  827. Private Sub ShowAxesCheck_Click()
  828.     CurveChoice_Click CurveNum
  829. End Sub
  830.  
  831.  
  832. Private Sub ThetaText_Change()
  833.     If ShowingParameters Then Exit Sub
  834.     EyeTheta = CSng(ThetaText.Text)
  835.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  836.     DrawData Pict
  837. End Sub
  838.  
  839.